<?php
/**
 * Advanced User Agent Displayer
 * 
 * @package Advanced User Agent Displayer 
 * @author Reza Moallemi<br/>(Port here by <a href="http://xiazhengxin.name/">Sharl</a>)
 * @version 2.7
 * @link http://www.moallemi.ir/blog
 */
	
class advanceduseragentdisplayer_Plugin implements Typecho_Plugin_Interface {

	public static function activate(){
		return _t('xxxxxx');
	}
	
	public static function deactivate(){}
	
	public static function config(Typecho_Widget_Helper_Form $form){
		$auad_options = advanceduseragentdisplayer_Plugin::get_auad_options();
		$checkBoxOptions = array('checked' => 'true');
		$selectOptions = array('selected' => 'true');
		
		//$name = NULL, array $options = NULL, $value = NULL, $label = NULL, $description = NULL
		
		$general_show_unknown = new Typecho_Widget_Helper_Form_Element_Checkbox('general_show_unknown', $auad_options['general_show_unknown'] == 'true' ? $checkBoxOptions : NULL, 'true', _t('general_show_unknown'), _t('icons if the browser and user agent are unknown'));
		
		$show_in_dashboard = new Typecho_Widget_Helper_Form_Element_Checkbox('show_in_dashboard', $auad_options['show_in_dashboard'] == 'true' ? $checkBoxOptions : NULL, 'true', _t('show_in_dashboard'), _t('Show browser and platform icons in the dashboard comments'));
		
		$post_show_browser = new Typecho_Widget_Helper_Form_Element_Checkbox('post_show_browser', $auad_options['post_show_browser'] == 'true' ? $checkBoxOptions : NULL, 'true', _t('post_show_browser'), _t('Show browser icon'));
		
		$post_show_platform = new Typecho_Widget_Helper_Form_Element_Checkbox('post_show_platform', $auad_options['post_show_platform'] == 'true' ? $checkBoxOptions : NULL, 'true', _t('post_show_platform'), _t('show platform icon'));
		
		$update_auad_settings = new Typecho_Widget_Helper_Form_Element_Submit('update_auad_settings', NULL, 'true', _t('Save Changes'), _t('show platform icon'));
		
		$post_location = new Typecho_Widget_Helper_Form_Element_Select('post_location',$selectOptions,NULL,_t('post_location'),'Display location');
		
		
/* 								  <option value="pl_author" <?php if ($auad_options['post_location'] == 'pl_author' ) echo ' selected="selected" '; ?> ><?php _e('After comment author name', 'advanced-user-agent-displayer'); ?></option>
								  <option value="pl_date" <?php if ($auad_options['post_location'] == 'pl_date' ) echo ' selected="selected" '; ?> ><?php _e('After comment date', 'advanced-user-agent-displayer'); ?></option>
								  <option value="pl_before" <?php if ($auad_options['post_location'] == 'pl_before' ) echo ' selected="selected" '; ?> ><?php _e('Before comment text', 'advanced-user-agent-displayer'); ?></option>
								  <option value="pl_after" <?php if ($auad_options['post_location'] == 'pl_after' ) echo ' selected="selected" '; ?> ><?php _e('After comment text', 'advanced-user-agent-displayer'); ?></option> */
		
		$post_icon_size = new Typecho_Widget_Helper_Form_Element_Select('post_icon_size',$selectOptions,NULL,_t('post_icon_size'),'Icon size');
		
/* 								  <option value="16" <?php if ($auad_options['post_icon_size'] == '16' ) echo ' selected="selected" '; ?> >16 px</option>
								  <option value="18" <?php if ($auad_options['post_icon_size'] == '18' ) echo ' selected="selected" '; ?> >18 px</option>
								  <option value="20" <?php if ($auad_options['post_icon_size'] == '20' ) echo ' selected="selected" '; ?> >20 px</option>
								  <option value="22" <?php if ($auad_options['post_icon_size'] == '22' ) echo ' selected="selected" '; ?> >22 px</option>
								  <option value="24" <?php if ($auad_options['post_icon_size'] == '24' ) echo ' selected="selected" '; ?> >24 px</option> */
		
        $form->addInput($general_show_unknown);
		$form->addInput($show_in_dashboard);
		$form->addInput($post_show_browser);
		$form->addInput($post_show_platform);
		$form->addInput($update_auad_settings);
	}
	
	public static function personalConfig(Typecho_Widget_Helper_Form $form){}
	
	public static function get_auad_options(){
		$auad_options = array('post_icon_size' => '20',
								'post_show_browser' => 'true',
								'post_show_platform' => 'true',
								'general_show_unknown' => 'false',
								'post_location' => 'pl_before',
								'show_in_dashboard' => 'true');
		return $auad_options;
	}
	
	public static function display_user_agent($str)
	{
		require_once 'include/browser.php';
		$plugin_url = Helper::options()->index.'/../usr/plugins/advanceduseragentdisplayer';
		$auad_options = advanceduseragentdisplayer_Plugin::get_auad_options();
		$browser = new Browser($str);
		if($auad_options['general_show_unknown'] == 'true' and $browser->Name == "Unknown" and $browser->Platform == "Unknown") return;
		$auad_string = '<img width="'.$auad_options['post_icon_size'].'" height="'.$auad_options['post_icon_size'].'" src="'.$plugin_url.'/img/24/net/'.$browser->BrowserImage.'.png" alt="'.$browser->Name.' '.$browser->Version.'" title="'.$browser->Name.' '.$browser->Version.'"> ';
		$auad_string .= '<img width="'.$auad_options['post_icon_size'].'" height="'.$auad_options['post_icon_size'].'" src="'.$plugin_url.'/img/24/os/'.$browser->PlatformImage.'.png" alt="'.$browser->Platform.' '.$browser->Pver.'" title="'.$browser->Platform.' '.$browser->Pver.' '.$browser->Architecture.'">';
			
		return "&nbsp;".$auad_string;
	}
}